﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using MiragePWF.Common.Container;
using MiragePWF.Common.Messages;

namespace Wolfut.MirageEE.UI.UICommonUtilities
{
    public class CustomerShowMessage
    {
        //************peter*******************
        //private const string KEY_MESSAGE_PROVIDER_NAME = "messageProviderName";
        //public static string m_msgProviderKey = "message.PCS.Zeus";
        private const string CAPTION_MESSAGE = "信息";
        private const string CAPTION_ERROR = "错误";
        private const string CAPTION_CONFIRM = "确认";
        private const string CAPTION_WARN = "警告";

        private const string LEVEL_CONFIRM = "确认";
        private const string CONFIRM_FORM_CLOSE_MESSAGE = "I40005";

        public static void ShowTransactionInfo(string successTransactionInfo)
        {
            //ShowMessage("I20009", successTransactionInfo);
        }
        public static void ShowTransactionInfo()
        {
            //ShowMessage("I20009");
        }
        public static DialogResult ShowErrorMessage(string message)
        {
            return MessageBox.Show(message, CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        public static DialogResult ShowInformationMessage(string message)
        {
            return MessageBox.Show(message, CAPTION_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static DialogResult ShowClosingMessage(string messageId, params string[] paraList)
        {
            DialogResult result = DialogResult.Yes;
            MessageBoxDefaultButton defButton = MessageBoxDefaultButton.Button1;
            if (CONFIRM_FORM_CLOSE_MESSAGE == messageId)
            {
                defButton = MessageBoxDefaultButton.Button2;
            }
            IMessageProvider m_messageProvider = IOC.Resolve<IMessageProvider>();
            if ((m_messageProvider == null))
            {
                MessageBox.Show("没有找到此系统消息!", CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string message = m_messageProvider.GetMessage(messageId, paraList);
                if (!(paraList == null & paraList.Length > 0))
                {
                    message = string.Format(message, paraList);
                }
                MessageSeverity msgLevel = m_messageProvider.GetMessageSeverity(messageId);
                if ((msgLevel == MessageSeverity.Unknown | msgLevel == MessageSeverity.Default))
                {
                    result = MessageBox.Show(message, CAPTION_CONFIRM, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, defButton);
                }
                else
                {
                    if (msgLevel == MessageSeverity.Error | msgLevel == MessageSeverity.Fatal)
                    {
                        MessageBox.Show(message, CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (msgLevel == MessageSeverity.Info)
                    {
                        MessageBox.Show(message, CAPTION_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (msgLevel == MessageSeverity.Warn)
                    {
                        MessageBox.Show(message, CAPTION_WARN, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (msgLevel == MessageSeverity.Debug)
                    {
                        System.Diagnostics.Debug.WriteLine(message);
                    }
                }
            }
            return result;
        }
        public static DialogResult ShowMessage(string messageId, params string[] paraList)
        {
            DialogResult result = DialogResult.Yes;
            MessageBoxDefaultButton defButton = MessageBoxDefaultButton.Button1;
            if (CONFIRM_FORM_CLOSE_MESSAGE == messageId)
            {
                defButton = MessageBoxDefaultButton.Button2;
            }
            IMessageProvider m_messageProvider = IOC.Resolve<IMessageProvider>();
            if ((m_messageProvider == null))
            {
                MessageBox.Show("没有找到此系统消息!", CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string message = m_messageProvider.GetMessage(messageId, paraList);
                if (!(paraList == null & paraList.Length > 0))
                {
                    message = string.Format(message, paraList);
                }
                MessageSeverity msgLevel = m_messageProvider.GetMessageSeverity(messageId);
                if ((msgLevel == MessageSeverity.Unknown | msgLevel == MessageSeverity.Default))
                {
                    result = MessageBox.Show(message, CAPTION_CONFIRM, MessageBoxButtons.YesNo, MessageBoxIcon.Question, defButton);
                }
                else
                {
                    if (msgLevel == MessageSeverity.Error | msgLevel == MessageSeverity.Fatal)
                    {
                        MessageBox.Show(message, CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (msgLevel == MessageSeverity.Info)
                    {
                        MessageBox.Show(message, CAPTION_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (msgLevel == MessageSeverity.Warn)
                    {
                        MessageBox.Show(message, CAPTION_WARN, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (msgLevel == MessageSeverity.Debug)
                    {
                        System.Diagnostics.Debug.WriteLine(message);
                    }
                }
            }
            return result;
        }
        public static DialogResult ShowCustomMessage(string messageId, string message)
        {
            DialogResult result = DialogResult.Yes;
            IMessageProvider m_messageProvider = IOC.Resolve<IMessageProvider>();
            if ((m_messageProvider == null))
            {
                MessageBox.Show("没有找到此系统消息!", CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageSeverity msgLevel = m_messageProvider.GetMessageSeverity(messageId);
                if ((msgLevel == MessageSeverity.Unknown | msgLevel == MessageSeverity.Default))
                {
                    result = MessageBox.Show(message, CAPTION_CONFIRM, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                }
                else
                {
                    if (msgLevel == MessageSeverity.Error | msgLevel == MessageSeverity.Fatal)
                    {
                        MessageBox.Show(message, CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (msgLevel == MessageSeverity.Info)
                    {
                        MessageBox.Show(message, CAPTION_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (msgLevel == MessageSeverity.Warn)
                    {
                        MessageBox.Show(message, CAPTION_WARN, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (msgLevel == MessageSeverity.Debug)
                    {
                        System.Diagnostics.Debug.WriteLine(message);
                    }
                }
            }
            return result;
        }
        public static DialogResult ShowCustomMessage(string[] messageId, string[] message)
        {
            string displayMsg = string.Empty;
            if ((messageId.Length == 0 | message.Length == 0))
            {
                MessageBox.Show("没有找到此系统消息!", CAPTION_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            for (Int32 index = 0; index <= messageId.Length - 1; index++)
            {
            }
            MessageBox.Show(displayMsg, CAPTION_MESSAGE, MessageBoxButtons.OK, MessageBoxIcon.Information);
            return DialogResult.Yes;
        }
        public static bool ConfirmProceed(string additionInfo)
        {
            if (ShowMessage("W00002", additionInfo) == DialogResult.No)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
